<template>
	<view class="indexs">
		<view class="header header_lan" :style="'padding-top: ' + navH + 'px;'">
			<view class="header_height" :style="'height:' + gaodu + 'px;line-height:' + gaodu + 'px;top:' + gaodutops + 'px;'">
				<view class="index_h_cont3">
					<view class="index_wenben_img" @tap="jumpzuo"><image :src="imgUrl + '/dzx_img22.png'" mode="widthFix"></image></view>
					<view class="index_wenben baise">{{ $t('page_baoguoyg.package_forecast') }}</view>
				</view>
			</view>
			<view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;padding-bottom: 120rpx;'">
			<view class="baoguo_item1">
				<view class="baoguo_item1_list" v-if="userclient.yubao.is_single==1 && userclient.yubao.is_more==1">
					<view v-if="userclient.yubao.is_single==1" :class="'baoguo_item1_cont ' + (baoguo_on == 0 ? 'on' : '')" @tap="danbtns" data-id="0">{{ $t('page_baoguoyg.single_courier_number') }}</view>
					<view v-if="userclient.yubao.is_more==1" :class="'baoguo_item1_cont ' + (baoguo_on == 1 ? 'on' : '')" @tap="danbtns" data-id="1">{{ $t('page_baoguoyg.multiple_tracking_numbers') }}</view>
				</view>
				<view class="baoguo_item1_xian" v-if="userclient.yubao.is_single==1 && userclient.yubao.is_more==1">
					<view class="baoguo_item1_banner" :style="'left:' + (baoguo_on == 0 ? '0%' : '50%')"><view class="baoguo_item1_lan"></view></view>
				</view>
			</view>
			<view class="baoguo_center">
				<view class="baoguo_item2">
					<view class="baoguo_item2_cont" @tap="guojiatz" v-if="userclient.yubao.is_country==1">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img23.png'"></image>
							<text>{{ $t('page_baoguoyg.shipping_country') }}</text>
						</view>
						<view class="baoguo_item2_cont_r">
							<text>{{ guojiaid>=0 ? guojianame : $t('page_baoguoyg.choose_country') }}</text>
							<image :src="imgUrl + '/dzx_img25.png'"></image>
						</view>
					</view>
					<view class="baoguo_item2_cont" v-if="userclient.yubao.is_shop==1">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img24.png'"></image>
							<text>{{ $t('page_baoguoyg.consolidation_warehouse') }}</text>
						</view>
						<picker @change="bindPickerChange" :value="index" :range="cangkuarray">
							<view class="baoguo_item2_cont_r">
								<text>{{ cangkuarray[index] }}</text>
								<image :src="imgUrl + '/dzx_img25.png'"></image>
							</view>
						</picker>
					</view>
				</view>
				<view class="baoguo_item2" v-if="baoguo_on == 0">
					<view class="baoguo_item2_cont" v-if="userclient.yubao.is_expressname==1">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img26.png'"></image>
							<text>{{ $t('page_baoguoyg.courier_name') }}</text>
						</view>
						<picker @change="bindKuaidiChange" :value="index" :range="kuaidirray">
							<view class="baoguo_item2_cont_r">
								<text>{{ kuaidirray[indexkd] }}</text>
								<image :src="imgUrl + '/dzx_img25.png'"></image>
							</view>
						</picker>
					</view>
					<view class="baoguo_item2_cont" v-if="userclient.yubao.is_expressnum==1">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img27.png'"></image>
							<text>{{ $t('page_baoguoyg.tracking_number') }}</text>
						</view>
						<view class="baoguo_item2_cont_r">
							<input type="text" :placeholder="$t('page_baoguoyg.please_enter_tracking_number')" @input="kuaididanhaoFun" :value="kuaididanhao" />
						</view>
					</view>
					<view class="baoguo_item2_cont2" v-if="userclient.yubao.is_goodslist==1">
						<view class="baoguo_item2_cont_l">
							<view class="">
								<image :src="imgUrl + '/dzx_img30.png'"></image>
								<text>{{ $t('page_baoguoyg.goodsinformation') }}</text>
							</view>
							<view>
								<button @tap="getData" class="addpack">+</button>
							</view>
						</view>
						<view class="baoguo_item2_cont_txttb" >
							<view  class="yunfeigusuan_item2_list" v-for="(goods,index) in goodslist">
								<uni-collapse ref="collapse" v-model="value">
									<uni-collapse-item :title="goods.pinming?goods.pinming:'请输入物品名称'" open="true" show-animation="true">
										<view class="yunfeigusuan_item2_cont">
											<input v-if="userclient.goods.is_barcode==1" type="text" :placeholder="$t('page_baoguoyg.barcode')" :data-index="index" :value="goods.barcode" @input="barcodeFun"/>
											<view style="margin-right: 5px;">
												<button @tap="deleteData(index)" class="addpack">-</button>
											</view>
											
											<view>
												<button @tap="getScancode(index)" class="cangkuyuan_saomaruku_item2_r1">
													<image :src="imgUrl+'/dzx_img196.png'" ></image>
												</button>
											</view>
										</view>
										<view v-if="userclient.goods.is_goods_name==1" class="yunfeigusuan_item2_cont">
											<input type="text" :placeholder="$t('page_baoguoyg.pinming')" :data-index="index" :value="goods.pinming" @input="pinmingFun" />
											<view>
												<button @tap="jumptosearchgoods(index)" class="cangkuyuan_saomaruku_item2_r1">
													<image :src="imgUrl+'/searchgoods.png'" ></image>
												</button>
											</view>
										</view>
										<view v-if="userclient.goods.is_goods_name_en==1" class="yunfeigusuan_item2_cont">
											<input type="text" :placeholder="$t('page_baoguoyg.goods_name_en')" :data-index="index" :value="goods.goods_name_en" @input="goodsnameenFun" />
										</view>
										<view v-if="userclient.goods.is_goods_name_jp==1" class="yunfeigusuan_item2_cont">
											<input type="text" :placeholder="$t('page_baoguoyg.goods_name_jp')" :data-index="index" :value="goods.goods_name_jp" @input="goodsnamejpFun" />
										</view>
										<view style="display: flex;">
											<view v-if="userclient.goods.is_price==1" class="yunfeigusuan_item2_cont">
												<input type="digit" :placeholder="$t('page_baoguoyg.danjia')" :data-index="index" :value="goods.danjia" @input="danjiaFun" />
											</view>
											<view class="yunfeigusuan_item2_cont">
												<input type="number" :placeholder="$t('page_baoguoyg.shuliang')" :data-index="index" :value="goods.shuliang" @input="shuliangFun" />
											</view>
										</view>
										<view style="display: flex;">
											<view v-if="userclient.goods.is_gross_weight==1" class="yunfeigusuan_item2_cont">
												<input type="digit" :placeholder="$t('page_baoguoyg.gross_weight')" :data-index="index" :value="goods.gross_weight" @input="grossweightFun" />
											</view>
											<view v-if="userclient.goods.is_net_weight==1" class="yunfeigusuan_item2_cont">
												<input type="digit" :placeholder="$t('page_baoguoyg.net_weight')" :data-index="index" :value="goods.net_weight" @input="netweightFun" />
											</view>
										</view>
										<view style="display: flex;">
											<view v-if="userclient.goods.is_brand==1" class="yunfeigusuan_item2_cont">
												<input type="text" :placeholder="$t('page_baoguoyg.brand')" :data-index="index" :value="goods.brand" @input="brandFun" />
											</view>
											<view v-if="userclient.goods.is_spec==1" class="yunfeigusuan_item2_cont">
												<input type="text" :placeholder="$t('page_baoguoyg.spec')" :data-index="index" :value="goods.spec" @input="specFun" />
											</view>
										</view>
										<view v-if="userclient.goods.is_depth==1" style="display: flex;">
											<view class="yunfeigusuan_item2_cont">
												<input type="digit" :placeholder="$t('page_baoguoyg.depth')" :data-index="index" :value="goods.depth" @input="depthFun" />
											</view>
											<view class="yunfeigusuan_item2_cont">
												<input type="digit" :placeholder="$t('page_baoguoyg.width')" :data-index="index" :value="goods.width" @input="widthFun" />
											</view>
											<view class="yunfeigusuan_item2_cont">
												<input type="digit" :placeholder="$t('page_baoguoyg.height')" :data-index="index" :value="goods.height" @input="heightFun" />
											</view>
										</view>
												
										
									</uni-collapse-item>
								</uni-collapse>
								
							</view>
						</view>
					</view>
					
					<view class="baoguo_item2_cont" @tap="shangpinpinlei" v-if="userclient.yubao.is_category==1">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img28.png'"></image>
							<text>{{ $t('page_baoguoyg.item_category') }}</text>
						</view>
						<view class="baoguo_item2_cont_r">
							<text>{{ shangpinnames }}</text>
							<image :src="imgUrl + '/dzx_img25.png'"></image>
						</view>
					</view>
					<view class="baoguo_item2_cont" v-if="userclient.yubao.is_price==1">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img29.png'"></image>
							<text>{{ $t('page_baoguoyg.item_value') }}({{ setting.unit }})</text>
						</view>
						<view class="baoguo_item2_cont_r">
							<input type="digit" :value="wupinjiazhi" @input="wupinjiazhiFun" :placeholder="$t('page_baoguoyg.please_enter_item_value')" />
						</view>
					</view>
					<view class="baoguo_item2_cont2" v-if="userclient.yubao.is_remark==1">
						<view class="baoguo_item2_cont_l" style="justify-content: flex-start;">
							<image :src="imgUrl + '/dzx_img30.png'"></image>
							<text>{{ $t('page_baoguoyg.commodity_remarks') }}</text>
						</view>
						<view class="baoguo_item2_cont_txt">
							<textarea @input="shangpinbeizhuFun" :value="shangpinbeizhu" :placeholder="$t('page_baoguoyg.please_enter_note') + '...'" name="" id="" cols="30" rows="10"></textarea>
						</view>
					</view>
					<view class="cangkuyuan_saomaruku_item1_cont2" style="border-bottom: none" v-if="userclient.yubao.is_images==1">
						<view class="cangkuyuan_saomaruku_item1_cont_l">
							<image :src="imgUrl + '/dzx_img192.png'"></image>
							<text>{{ $t('page_baoguoyg.photo_upload') }}</text>
						</view>
						<view class="cangkuyuan_saomaruku_item2_r5" @click="toSelectImage()">
							<view v-for="item in imageSrc" :key="index" class="cangkuyuan_saomaruku_item2_r5_img"><image :src="item"></image></view>
							<view class="cangkuyuan_saomaruku_item2_r5_img"><image :src="imgUrl + '/dzx_img193.png'"></image></view>
						</view>
					</view>
				</view>

				<view class="baoguo_item2" v-if="baoguo_on == 1">
					<view class="baoguo_item2_cont">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img27.png'"></image>
							<text>{{ $t('page_baoguoyg.tracking_number') }}</text>
						</view>
						<view class="baoguo_item2_cont_r">
							<input type="text" :placeholder="$t('page_baoguoyg.please_enter_tracking_number')" :value="duokuaididan" @input="duokuaididanhaoFun" />
						</view>
						<view><button @tap="addpack" class="addpack">+</button></view>
					</view>
					<view class="baoguo_item2_cont2" style="border-bottom: 1px solid #efefef">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img27.png'"></image>
							<text>{{ $t('page_baoguoyg.multiple_tracking_numbers_point') }}</text>
						</view>
						<view class="baoguo_item2_cont_txt"><textarea @input="kuaididanhaoChange" name="" id="" cols="30" rows="10" :value="kuaididanhao"></textarea></view>
						<view class="baoguo_item2_cont_zhuyi">{{ $t('page_baoguoyg.multiple_tracking_numbers_hint_text') }}</view>
					</view>
					<view class="baoguo_item2_cont" @tap="shangpinpinlei" v-if="userclient.yubao.is_category==1">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img28.png'"></image>
							<text>{{ $t('page_baoguoyg.item_category') }}</text>
						</view>
						<view class="baoguo_item2_cont_r">
							<text>{{ shangpinnames }}</text>
							<image :src="imgUrl + '/dzx_img25.png'"></image>
						</view>
					</view>
					<view class="baoguo_item2_cont" v-if="userclient.yubao.is_price==1">
						<view class="baoguo_item2_cont_l">
							<image :src="imgUrl + '/dzx_img29.png'"></image>
							<text>{{ $t('page_baoguoyg.item_value') }}({{ setting.unit }})</text>
						</view>
						<view class="baoguo_item2_cont_r">
							<input type="digit" :value="wupinjiazhi" @input="wupinjiazhiFun" :placeholder="$t('page_baoguoyg.please_enter_item_value')" />
						</view>
					</view>
					<view class="baoguo_item2_cont2" v-if="userclient.yubao.is_remark==1">
						<view class="baoguo_item2_cont_l" style="justify-content: flex-start;">
							<image :src="imgUrl + '/dzx_img30.png'"></image>
							<text>{{ $t('page_baoguoyg.commodity_remarks') }}</text>
						</view>
						<view class="baoguo_item2_cont_txt">
							<textarea :value="shangpinbeizhu" @input="shangpinbeizhuFun" :placeholder="$t('page_baoguoyg.please_enter_note') + '...'" name="" id="" cols="30" rows="10"></textarea>
						</view>
					</view>
				</view>
				<view class="baoguo_item3" @tap="btnisshow" v-if="userclient.yubao.is_xieyi==1">
					<image :src="imgUrl + (isshow ? 'dzx_img31.png' : 'dzx_img32.png')"></image>
					<view class="baoguo_item3_txt">{{ $t('page_baoguoyg.viewed_and_agreed') }}</view>
					<view class="baoguo_item3_txt1" @tap="guizeshows">《{{ guizes.article_title }}》</view>
				</view>
				<view class="baoguo_btns">
					<view class="baoguo_btns_posi">
						<view class="baoguo_btn" @tap="netxstep">{{ $t('page_baoguoyg.netxstep') }}</view>
					</view>
				</view>
			</view>

			<view class="baoguo_guize" v-if="guizeshow" >
				<view class="baoguo_guize_banner">
					<view class="baoguo_guize_title">《{{ guizes.article_title }}》</view>
					<view class=""><rich-text :nodes="article_content?article_content:''"></rich-text></view>
					<view class="baoguo_guize_btns" @tap="isguizeshows">
						<view class="baoguo_guize_btns_txt">{{ $t('page_baoguoyg.iSee') }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
// pages/shouye/shouye_zkc/shouye_zkc.js
const app = getApp();

let request = require('../../../utils/require');
let platfrom = require('../../../core/platform.js')
export default {
	data() {
		return {
			navH: app.globalData.navHeight,
			tijiaoshow:true,
			platfrom:platfrom.default,
			gaodu: app.globalData.height,
			gaodutops: app.globalData.top,
			imgUrl: app.globalData.imgUrl,
			baoguo_on: 0,
			isshow: false,
			guojiaid: '',
			guojianame: '请选择国家',
			cangkuarray: [],
			index: 0,
			kuaidirray: [],
			goodslist:[{
				barcode:'',
				pinming:'',
				goods_name_en:'',
				goods_name_jp:'',
				brand:'',
				spec:'',
				gross_weight:'',
				net_weight:'',
				depth:'',
				width:'',
				height:'',
				danjia:'',
				shuliang:1,
			}],
			indexkd: 0,
			shangpinids: '',
			shangpinnames: '请选择商品品类',
			guizeshow: false,
			kuaididanhao: '',
			kuaididan: '',
			duokuaididan: '',
			wupinjiazhi: '',
			shangpinbeizhu: '',
			// address_id:0,
			share_id: 0,
			guizes: {
				article_title: ''
			},
			article_content: '',
			kuaidilist: '',
			arrlist: [],
			cangkuarr: '',
			template_ids: '',
			imageSrc: [],
			imageIds: [],
			sku_id:0,
			sku_index:0,
			
			setting: uni.getStorageSync('price_mode'),
			userclient: uni.getStorageSync('userclient')
		};
	},
	/**
	 * 生命周期函数--监听页面加载
	 */ 
	onLoad() {
		var that = this;
		if(that.userclient.yubao.is_single==0){
			that.baoguo_on = 1
		}
		that.servicesetting();
		// that.getCountryName();
	},
	onShow() {
		var that = this;
		that.getSubTemplate();
		that.cangkulist();
		that.kuaidilistFun();
		that.guize(); //返回国家id
		let pages = getCurrentPages();
		let currPage = pages[pages.length - 1];
		if (currPage.options.from == 'sharp' && currPage.options.share_id) {
			this.share_id = currPage.options.share_id;
			this.initShareData(this.share_id);
		}
		// #ifdef MP-WEIXIN
		if (currPage.data && currPage.data.sku_id) {
			that.sku_id = currPage.data.sku_id;
			that.getSkuplus(that.sku_index,that.sku_id);
		}
		// #endif
		// #ifdef H5
		if (currPage && currPage.sku_id) {
			that.sku_id = currPage.data.sku_id
			that.getSkuplus(that.sku_index,that.sku_id);
		}
		// #endif
		that.guojiaid = currPage.guojiaid || ''
		that.guojianame = currPage.guojianame || ''
		if (currPage.ids) {
			this.shangpinids = currPage.ids
			this.shangpinnames = currPage.names //返回商品品类
		}
		that.sku_id = '';
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {},
	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {},
	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {},
	methods: {
		getSkuplus(a,e){
			var that = this;
			var data = {
				token: uni.getStorageSync('token'),
				barcode:e
			};
			request.post(`index.php?s=/api/page/getbarcode&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					if(res.data.data){
						console.log(res.data.data.barcode,999);
						for (var i = 0; i < that.goodslist.length; i++) {
							if(that.goodslist[i].barcode ==  res.data.data.barcode){
								that.goodslist[i].shuliang = Number(that.goodslist[i].shuliang) + 1;
								that.wupinjiazhi = Number(that.wupinjiazhi) + Number(that.goodslist[i].danjia)
								return;
							}
						}
						this.wupinjiazhi = Number(that.wupinjiazhi) - Number(this.goodslist[a].danjia) * Number(this.goodslist[a].shuliang ) + Number(res.data.data.price)* Number(this.goodslist[a].shuliang )
						this.goodslist[a].barcode = res.data.data.barcode
						this.goodslist[a].pinming = res.data.data.goods_name
						this.goodslist[a].danjia = res.data.data.price
						this.goodslist[a].goods_name_en = res.data.data.goods_name_en
						this.goodslist[a].goods_name_jp = res.data.data.goods_name_jp
						this.goodslist[a].brand = res.data.data.brand
						this.goodslist[a].spec = res.data.data.spec
						this.goodslist[a].gross_weight = res.data.data.gross_weight
						this.goodslist[a].net_weight = res.data.data.net_weight
						this.goodslist[a].depth = res.data.data.depth
						this.goodslist[a].width = res.data.data.width
						this.goodslist[a].height = res.data.data.height
						
					}else{
						this.goodslist[a].barcode = e
					}
					
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});
				}
			});
		},
		jumptosearchgoods(e){
			var index = e;
			this.sku_index = e,
			uni.navigateTo({
				url: '/pages/indexs/goodslist/goodslist?search=' + this.goodslist[index].pinming 
			});
		},
		//扫码
		getScancode: function (e) {
		    var that = this;
		    uni.scanCode({
		        //扫描API
		        scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
		
		        success(res) {
					console.log(res,99000)
		            //扫描成功
					that.getSku(e,res.result);
		        }
		    });
		},
		getSku(a,e){
			var that = this;
			var data = {
				token: uni.getStorageSync('token'),
				barcode:e
			};
			request.post(`index.php?s=/api/page/getbarcode&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					if(res.data.data){
						console.log(res.data.data.barcode,999);
						for (var i = 0; i < that.goodslist.length; i++) {
							if(that.goodslist[i].barcode ==  res.data.data.barcode){
								that.goodslist[i].shuliang = Number(that.goodslist[i].shuliang) + 1;
								that.wupinjiazhi = Number(that.wupinjiazhi) + Number(that.goodslist[i].danjia)
								return;
							}
						}
						console.log(a,9909)
						this.wupinjiazhi = Number(that.wupinjiazhi) - Number(this.goodslist[a].danjia) * Number(this.goodslist[a].shuliang ) + Number(res.data.data.price)* Number(this.goodslist[a].shuliang )
						this.goodslist[a].barcode = res.data.data.barcode
						this.goodslist[a].pinming = res.data.data.goods_name
						this.goodslist[a].danjia = res.data.data.price
						this.goodslist[a].goods_name_en = res.data.data.goods_name_en
						this.goodslist[a].goods_name_jp = res.data.data.goods_name_jp
						this.goodslist[a].brand = res.data.data.brand
						this.goodslist[a].spec = res.data.data.spec
						this.goodslist[a].gross_weight = res.data.data.gross_weight
						this.goodslist[a].net_weight = res.data.data.net_weight
						this.goodslist[a].depth = res.data.data.depth
						this.goodslist[a].width = res.data.data.width
						this.goodslist[a].height = res.data.data.height
						// this.wupinjiazhi =  Number(that.wupinjiazhi) + Number(res.data.data.price)  
					}else{
						this.goodslist[a].barcode = e
					}
					
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});
				}
			});
		},
		netxstep(){
			var that = this;
			var data = {
				country_id: that.guojiaid,
				//国家id
				express_id: that.kuaidilist[that.indexkd].express_id,
				//快递id
				storage_id: that.cangkuarr[that.index].shop_id,
				//仓库id
				class_ids: that.shangpinids,
				//物品品类
				price: that.wupinjiazhi,
				//物品价值
				express_sn: that.kuaididanhao,
				//快递单号
				remark: that.shangpinbeizhu,
				//商品备注
				//图片
				imageIds: that.imageIds,
				token: uni.getStorageSync('token'), //token用户登录凭证
				goodslist:that.goodslist,
			};
			if (this.share_id) {
				data['share_id'] = this.share_id;
				data['is_share'] = 1;
				// data['address_id'] = this.address_id;
			};
			
			
			if (that.guojiaid=='' && that.userclient.yubao.is_country==1 && that.userclient.yubao.is_country_force==1) {
				uni.showToast({
					title: '目标国家/地区不能为空',
					icon: 'none'
				});
				return;
			};
			if (data.storage_id=='' && that.userclient.yubao.is_shop && that.userclient.yubao.is_shop_force==1) {
				uni.showToast({
					title: '目标仓库不能为空',
					icon: 'none'
				});
				return;
			};
			if (that.express_id=='' && that.userclient.yubao.is_expressname==1 && that.userclient.yubao.is_expressname_force==1) {
				uni.showToast({
					title: '快递公司不能为空',
					icon: 'none'
				});
				return;
			};
			if (data.express_sn == '' && that.userclient.yubao.is_expressnum==1 && that.userclient.yubao.is_expressnum_force==1) {
				uni.showToast({
					title: '快递单号不可为空',
					icon: 'none'
				});
				return;
			};
			if (this.baoguo_on == 0 && data.goodslist[0].pinming =='' && that.userclient.yubao.is_goodslist==1 && that.userclient.yubao.is_goodslist_force==1) {
				uni.showToast({
					title: '物品信息不能为空',
					icon: 'none'
				});
				return;
			};
			if (that.shangpinids=='' && that.userclient.yubao.is_category==1 && that.userclient.yubao.is_category_force==1) {
				uni.showToast({
					title: '物品分类不能为空',
					icon: 'none'
				});
				return;
			};
			if ( that.wupinjiazhi == '' && that.userclient.yubao.is_price==1 && that.userclient.yubao.is_price_force==1) {
				uni.showToast({
					title: '物品价值不可为空',
					icon: 'none'
				});
				return ;
			};
			if (that.shangpinbeizhu=='' && that.userclient.yubao.is_remark==1 && that.userclient.yubao.is_remark_force==1) {
				uni.showToast({
					title: '必须填写备注信息',
					icon: 'none'
				});
				return;
			};
			if (this.baoguo_on == 0 && that.imageIds=='' && that.userclient.yubao.is_images==1 && that.userclient.yubao.is_images_force==1) {
				uni.showToast({
					title: '必须上传包裹图片',
					icon: 'none'
				});
				return;
			};
			if(!that.tijiaoshow){
				uni.showToast({
					title:"请勿重复提交",
					iocn:"none"
				})
			return false;
			}
			that.tijiaoshow = false;
			console.log(data,89786756);
			uni.navigateTo({
				url:"/pages/indexs/baoguoyg_dbnext/baoguoyg_dbnext?express=" + JSON.stringify(data)
			})
			setTimeout(function(){
				that.tijiaoshow = true;
			},1500)
		},
		servicesetting(){
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.post(`index.php?s=/api/page/service&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					that.userclient = res.data.data.userclient
					that.guojiaid = res.data.data.country.id
					that.guojianame = res.data.data.country.title
					that.country_id = res.data.data.country.id
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});
				}
				console.log(that.switchFunlist, 777);
			});
		},
		pinmingFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].pinming = e.detail.value;
			console.log(this.goodslist,990099);
		},
		danjiaFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].danjia = e.detail.value;
			this.wupinjiazhi = 0;
			if(index==0){
				this.wupinjiazhi = this.goodslist[index].danjia * this.goodslist[index].shuliang
			}else{
				for (var i = 0; i < index; i++) {
					this.wupinjiazhi += this.goodslist[i].danjia * this.goodslist[i].shuliang
				}
			}
			
		},
		shuliangFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].shuliang = e.detail.value;
			this.wupinjiazhi = 0;
			if(index==0){
				this.wupinjiazhi = this.goodslist[index].danjia * this.goodslist[index].shuliang
				
			}else{
				for (var i = 0; i <= index; i++) {
					this.wupinjiazhi = this.wupinjiazhi + this.goodslist[i].danjia * this.goodslist[i].shuliang
					console.log(this.wupinjiazhi,7876545)
				}
			}
		},
		deleteData(e){
			var that = this;
			that.wupinjiazhi = Number(that.wupinjiazhi) - Number(that.goodslist[e].danjia) * Number(that.goodslist[e].shuliang)
			this.goodslist.splice(e,1);
		},
		goodsnameenFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].goods_name_en = e.detail.value;
		},
		goodsnamejpFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].goods_name_jp = e.detail.value;
		},
		brandFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].brand = e.detail.value;
		},
		specFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].spec = e.detail.value;
		},
		depthFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].depth = e.detail.value;
		},
		widthFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].width = e.detail.value;
		},
		heightFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].height = e.detail.value;
		},
		barcodeFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].barcode = e.detail.value;
		},
		grossweightFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].gross_weight = e.detail.value;
		},
		netweightFun(e){
			var index = e.currentTarget.dataset.index;
			this.goodslist[index].net_weight = e.detail.value;
		},
		async getData() {
		  try {
			var a = [{
				barcode:'',
				pinming:'',
				goods_name_en:'',
				goods_name_jp:'',
				brand:'',
				spec:'',
				gross_weight:'',
				net_weight:'',
				depth:'',
				width:'',
				height:'',
				danjia:'',
				shuliang:1
				}];
			const res = this.goodslist.concat(a);
			this.goodslist = res;
		  } catch (err) {
			console.error(err)
		  }
		},
		toSelectImage() {
			var that = this;
			uni.chooseImage({
				count: 9, // 最多可以选择的图片张数，默认9
				sizeType: ['original', 'compressed'], //original 原图，compressed 压缩图，默认二者都有
				sourceType: ['album', 'camera'], //album 从相册选图，camera 使用相机，默认二者都有。如需直接开相机或直接选相册，请只使用一个选项
				success: function(res) {
					//判断图片格式
					uni.showLoading({
						title:'......'
					})
					console.log(res)
					for(var i=0;i<res.tempFiles.length;i++){
						if(res.tempFiles[0]['size']>2*1024*1024){
							uni.showToast({
								title: '图片大小不能超过2M',
								icon: 'none',
								duration: 3000
							});
							return;
						}
						
						that.uploadImgFile(res.tempFiles[0],that)
					}
				}
			});
		},
		uploadImgFile(filePath) {
			var that = this;
			uni.uploadFile({
				url: app.globalData['url'] + '/index.php?s=/api/upload/image&wxapp_id=' + uni.getStorageSync('web_id') + '&token=' + uni.getStorageSync('token'),
				filePath: filePath.path,
				name: 'iFile',
				success: response => {
					let res = JSON.parse(response.data);

					uni.hideLoading();
					if (res.code == 1) {
						that.imageSrc.push(res.data.file_path);
						that.imageIds.push(res.data.file_id);
					}
					console.log(that.imageSrc, '--666--res');
				},
				fail: err => {
					uni.hideLoading();
					console.log('请求失败_______________', err);
				}
			});
		},
		//验货规则
		guize() {
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.post(`index.php?s=/api/article/report_note&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					var article_content = res.data.data.detail.article_content;
					article_content = article_content.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ');
					that.guizes = res.data.data.detail
					that.article_content = article_content
				}
			});
		},
		selectAddress() {
			uni.navigateTo({
				url: '/pages/pintuans/dizhi/dizhi?type=xuanze'
			});
		},

		getStorageIndex(modelid) {
			var storagelist = this.cangkuarr;
			for (var l in storagelist) {
				if (storagelist[l]['shop_id'] == modelid) {
					return l;
				}
			}
			return false;
		},

		initShareData(share_id) {
			console.log('拼团包裹提交');
			uni.showLoading({
				title: this.$t('page_other.拼团数据获取中')
			});
			var that = this;
			var data = {
				token: uni.getStorageSync('token'),
				id: share_id
			};
			request.post(`index.php?s=/api/sharp.order/detail&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					var model = res.data.data.model;
					var storage_index = this.getStorageIndex(model['storage_id']);
					this.index = storage_index;
					this.guojiaid = model.country_id
					this.guojianame = model.country.title
					this.shop_id = model.storage_id
				}
			});
		},

		//快递单号
		duokuaididanhaoFun(e) {
			this.duokuaididan = e.detail.value
			console.log(e.detail.value, '?????');
		},
		//快递单号
		kuaididanhaoFun(e) {
			this.kuaididanhao = e.detail.value
			console.log(e.detail.value, '?????');
		},
		kuaididanhaoChange(e) {
			this.kuaididanhao = e.detail.value
		},
		addpack() {
			var that = this;
			var res = '';
			res = that.duokuaididan;
			if (that.duokuaididan == '') {
				uni.showToast({
					title:that.$t('page_other.请输入单号再点加号')
				});
				return;
			}

			if (that.kuaididanhao == '') {
				that.kuaididanhao = res
				that.duokuaididan = ''
				return;
			}
			that.kuaididanhao = res + ',' + that.kuaididanhao
			that.duokuaididan = ''
		},

		//商品备注
		shangpinbeizhuFun(e) {
			this.shangpinbeizhu = e.detail.value
		},

		//物品价值
		wupinjiazhiFun(e) {
			this.wupinjiazhi = e.detail.value
		},
		//清空快递单号
		clearkuaididanhao() {
			this.kuaididanhao = ''
		},
		clearall(){
			console.log(12121212);
			this.wupinjiazhi = '',
			this.shangpinbeizhu = '',
			this.imageIds = '',
			this.imageSrc = '',
			this.goodslist = [{pinming:"",shuliang:"",danjia:""}]
			
		},
		getCountryName() {
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.post(`index.php?s=/api/package/getCountryName&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					var model = res.data.data;
					if(model){
						this.guojiaid =  model.country_id
						this.guojianame =  model.country
					}else if(uni.getStorageSync('country') != null){
						this.guojiaid = uni.getStorageSync('country')['id']
						this.guojianame = uni.getStorageSync('country')['title']
					}
					
					console.log(that.guojiaid, 87654);
				}
			});
		},


		isguizeshows() {
			this.guizeshow = false
		},

		guizeshows() {
			this.guizeshow = true
		},

		//商品品类
		shangpinpinlei() {
			uni.navigateTo({
				url: '/pages/indexs/shangpinpinlei/shangpinpinlei'
			});
		},

		//选择国家
		guojiatz() {
			if (this.share_id) {
				uni.showToast({
					icon: 'none',
					title:this.$t('page_other.拼团订单无法自行选择国家')
				});
				return;
			}
			uni.navigateTo({
				url: '/pages/indexs/baoguoyg_guojia/baoguoyg_guojia'
			});
		},

		//快递列表
		kuaidilistFun() {
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.get(`index.php?s=/api/package/express&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					var arrlist = [];

					for (var i = 0; i < res.data.data.length; i++) {
						arrlist.push(res.data.data[i].express_name);
					}
					this.kuaidirray = arrlist
					this.kuaidilist = res.data.data
				}
			});
		},

		//仓库列表
		cangkulist() {
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.get(`index.php?s=/api/package/storage&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					var arrlist = [];
					for (var i = 0; i < res.data.data.length; i++) {
						arrlist.push(res.data.data[i].shop_name);
					}
					this.cangkuarray = arrlist
					this.cangkuarr = res.data.data
				}
			});
		},

		getSubTemplate: function() {
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.get(`index.php?s=/api/package/SubTempate&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					this.template_ids = res.data.data.template_ids
					console.log(this.template_ids);
				}
			});
		},

		//选择快递
		bindKuaidiChange: function(e) {
			this.indexkd = e.detail.value
		},

		//选择仓库
		bindPickerChange: function(e) {
			if (this.share_id) {
				uni.showToast({
					icon: 'none',
					title: this.$t('page_other.拼团订单无法自行选择仓库')
				});
				return;
			}
			this.index = e.detail.value
		},

		btnisshow() {
			this.isshow = !this.isshow
		},

		danbtns(e) {
			this.baoguo_on = e.currentTarget.dataset.id
			this.kuaididanhao = ''
			console.log(this.baoguo_on);
		},

		jumpzuo() {
			uni.navigateBack();
		}
	}
};
</script>
<style>
@import './baoguoygksdb.css';
</style>
